﻿(function () {
    'use strict';

    angular
        .module('app.dashboard')
        .factory('UserReferralData', UserReferralData);

    UserReferralData.$inject = ['$http','$mdDialog'];

    /* @ngInject */
    function UserReferralData($http, $mdDialog) {
        var service = {

            GetUserData:GetUserData,
            GetOutstandingReferrals: GetOutstandingReferrals,
            GetNewReferrals: GetNewReferrals,
            GetCompletedReferrals: GetCompletedReferrals,
            GetScheduledReferrals: GetScheduledReferrals,
            GetUserSections: GetUserSections,
            GetWeeklyStats: GetWeeklyStats,
            GetDailyStats: GetDailyStats,
            GetDailyReferralInStats: GetDailyReferralInStats,
            GetDailyReferralOutStats: GetDailyReferralOutStats,

            GetYesterdayStats: GetYesterdayStats,
            GetYesterdayReferralInStats: GetYesterdayReferralInStats,
            GetYesterdayReferralOutStats: GetYesterdayReferralOutStats,

            GetWeeklyPracticeStats: GetWeeklyPracticeStats,
            GetWeeklyReferralInStats: GetWeeklyReferralInStats,
            GetWeeklyReferralOutStats: GetWeeklyReferralOutStats,

            GetMonthlyStats: GetMonthlyStats,
            GetMonthlyReferralInStats: GetMonthlyReferralInStats,
            GetMonthlyReferralOutStats: GetMonthlyReferralOutStats,

            GetPreviousMonthlyStats: GetPreviousMonthlyStats,
            GetPreviousMonthlyReferralInStats: GetPreviousMonthlyReferralInStats,
            GetPreviousMonthlyReferralOutStats: GetPreviousMonthlyReferralOutStats

            //showToasts: true,

            //error: error,
            //info: info,
            //success: success,
            //warning: warning,

            //// straight to console; bypass toastr
            //log: $log.log
        };

        return service;
        /////////////////////
        var UserCategories;
        var InProcessRefs;
        var CompletedRefs;
        var NewRefs;
        var ScheduledRefs;
        var WeeklyStats;
        var DailyPracticeSplit;
        var DailyReferralInStats;
        var DailyReferralOutStats;

        var YesterdayPracticeSplit;
        var YesterdayReferralInStats;
        var YesterdayReferralOutStats;
        var WeeklyPracticeSplit;
        var WeeklyReferralInStats;
        var WeeklyReferralOutStats;
        var MonthlyPracticeSplit;
        var MonthlyReferralInStats;
        var MonthlyReferralOutStats;
        var PreviousMonthlyPracticeSplit;
        var PreviousMonthlyReferralInStats;
        var PreviousMonthlyReferralOutStats;


        var DataLoaded = false;

        function GetUserData(LoginID) {
            return $http.get(apiLocation + 'UserReferrals/' + LoginID).then(function (response) {
                UserCategories = response.data.ReferralCategories;
                NewRefs = response.data.NewRequests;
                InProcessRefs = response.data.InProcessRequests;
                CompletedRefs = response.data.CompletedRequests;
                ScheduledRefs = response.data.ScheduledRequests;
                WeeklyStats = response.data.WeeklyStats;

                DailyPracticeSplit = response.data.DailyPracticeSplit;
                DailyReferralInStats = response.data.DailyReferralInStat;
                DailyReferralOutStats = response.data.DailyReferralOutStat;

                YesterdayPracticeSplit = response.data.YesterdayPracticeSplit;
                YesterdayReferralInStats = response.data.YesterdayReferralInStat;
                YesterdayReferralOutStats = response.data.YesterdayReferralOutStat;

                WeeklyPracticeSplit = response.data.WeeklyPracticeSplit;
                WeeklyReferralInStats = response.data.WeeklyReferralInStat;
                WeeklyReferralOutStats = response.data.WeeklyReferralOutStat;

                MonthlyPracticeSplit = response.data.MonthlyPracticeSplit;
                MonthlyReferralInStats = response.data.MonthlyReferralInStat;
                MonthlyReferralOutStats = response.data.MonthlyReferralOutStat;

                PreviousMonthlyPracticeSplit = response.data.PreviousMonthlyPracticeSplit;
                PreviousMonthlyReferralInStats = response.data.PreviousMonthlyReferralInStat;
                PreviousMonthlyReferralOutStats = response.data.PreviousMonthlyReferralOutStat;

                DataLoaded = true;
            });
            
        }

        function GetOutstandingReferrals() {
            return InProcessRefs;
        }
        
        function GetScheduledReferrals() {
            return ScheduledRefs;
        }

        function GetCompletedReferrals() {
            return CompletedRefs;
        }

        function GetUserSections() {
            return UserCategories;
        }


        function GetNewReferrals() {
            return NewRefs;
        }

        function GetWeeklyStats() {
            return WeeklyStats;
        }

        function GetDailyStats() {
            return DailyPracticeSplit;
        }

        function GetDailyReferralOutStats() {
            return DailyReferralOutStats;
        }

        function GetDailyReferralInStats() {
            return DailyReferralInStats;
        }

        function GetYesterdayStats() {
            return YesterdayPracticeSplit;
        }

        function GetYesterdayReferralOutStats() {
            return YesterdayReferralOutStats;
        }

        function GetYesterdayReferralInStats() {
            return YesterdayReferralInStats;
        }


        function GetWeeklyPracticeStats() {
            return WeeklyPracticeSplit;
        }

        function GetWeeklyReferralOutStats() {
            return WeeklyReferralOutStats;
        }

        function GetWeeklyReferralInStats() {
            return WeeklyReferralInStats;
        }

        function GetMonthlyStats() {
            return MonthlyPracticeSplit;
        }

        function GetMonthlyReferralOutStats() {
            return MonthlyReferralOutStats;
        }

        function GetMonthlyReferralInStats() {
            return MonthlyReferralInStats;
        }


        function GetPreviousMonthlyStats() {
            return PreviousMonthlyPracticeSplit;
        }

        function GetPreviousMonthlyReferralOutStats() {
            return PreviousMonthlyReferralOutStats;
        }

        function GetPreviousMonthlyReferralInStats() {
            return PreviousMonthlyReferralInStats;
        }

    }
}());
